import { createClient } from "redis";

const redisClient = createClient({
    socket: {
        port: 6379,
        host:
            process.env.NODE_ENV !== "production"
                ? "118.178.104.159"
                : "127.0.0.1",
    },
    password: "x7MRxZ0y",
});
const prefix = "yzpt";

try {
    redisClient.connect();
} catch (err) {
    console.log(err);
}

export default {
    getVal: async (key = "") => {
        const res = await redisClient.get(`${prefix}-${key}`);
        return res;
    },

    setVal: async (key, value, options) => {
        await redisClient.set(`${prefix}-${key}`, value, options);
    },

    delVal: async (key) => {
        await redisClient.del(`${prefix}-${key}`);
    },
};
